import 'package:flutter/material.dart';

class ControlLifeView extends StatefulWidget {
  const ControlLifeView({ super.key });

// 先执行这个方法
  @override
  State<ControlLifeView> createState() {
    debugPrint("1.执行createState");
    return  _ControlLifeView();   
  }
}
// 私有类initState
class _ControlLifeView extends State<ControlLifeView> {
  
  int count = 0;
  @override
  void initState() {
    // TODO: implement initState
    debugPrint("2.执行InitState");
    super.initState();
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
     debugPrint("3.执行didChangeDependencies");
    super.didChangeDependencies();
  }
  @override
  void didUpdateWidget(covariant ControlLifeView oldWidget) {
    // TODO: implement didUpdateWidget
     debugPrint("5.执行didUpdateWidget"); // 该方法主要是组件重新构建时才会被调用的
     // 或者 父组件发生 build 时子组件的该方法就会被调用
    super.didUpdateWidget(oldWidget);
  }
  @override
  void deactivate() {
    // TODO: implement deactivate
    debugPrint("6.组件从节点移除时调用");
    super.deactivate();
  }
  @override
  void dispose() {
    // TODO: implement dispose
     debugPrint("7.内存释放时调用");
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    debugPrint("4.执行build方法, 会执行多次");

    return Column(
      children: [
        Text(count.toString()),
       ElevatedButton(
           onPressed: () {
             setState(() {
               count++;
             });
           },
           child: const Text('加'),
          )
      ],
    );
  }
}